using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    Player player;
    bool isJump;

    float lasttime;
    float cd;

    // Start is called before the first frame update
    void Start()
    {
        player = GetComponent<Player>();
        cd = 2;
        lasttime = Time.time - cd;
    }

    // Update is called once per frame
    void Update()
    {

        isJump = false;  
        float x = Input.GetAxis("Horizontal");
        if(Input.GetButtonDown("Jump"))
        {
            player.Attck();
        }
        if (Input.GetKeyDown(KeyCode.W)) isJump = true;
        player.move(x,isJump);

        if (Input.GetKeyDown(KeyCode.Q))
        {
            if (lasttime + cd < Time.time)
            {
                Instantiate(player.grenades, transform, false);
                lasttime = Time.time;
            }
        }

            if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            player.Bullet = player.ArmsBag[0];
            player.Gun.GetComponent<SpriteRenderer>().sprite = player.GunSprites[0];
        }

        if (Input.GetKeyDown(KeyCode.Alpha1) && Data.gun1)
        {
            player.Bullet = player.ArmsBag[1];
            player.Gun.GetComponent<SpriteRenderer>().sprite = player.GunSprites[1];
        }
        if (Input.GetKeyDown(KeyCode.Alpha2) && Data.gun2)
        {
            player.Bullet = player.ArmsBag[2];
            player.Gun.GetComponent<SpriteRenderer>().sprite = player.GunSprites[2];
        }
        if (Input.GetKeyDown(KeyCode.Alpha3) && Data.gun3)
        {
            player.Bullet = player.ArmsBag[3];
            player.Gun.GetComponent<SpriteRenderer>().sprite = player.GunSprites[3];
        }
        if (Input.GetKeyDown(KeyCode.Alpha4) && Data.gun4)
        {
            player.Bullet = player.ArmsBag[4];
            player.Gun.GetComponent<SpriteRenderer>().sprite = player.GunSprites[4];
        }
    }
}
